// Copyright (C) 2025, ZWSOFT Co., LTD.(Guangzhou)
// Licensed under the MIT License. See LICENSE in the project root for license information.

using CommunityToolkit.Mvvm.ComponentModel;
using MaterialDesignThemes.Wpf;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.ObjectModel;
using System.Windows;
using TestClient.Views;

namespace TestClient.ViewModel;

public partial class MainWindowViewModel : ObservableObject
{
    public SnackbarMessageQueue SnackbarMessageQueue { get; } =
        new(TimeSpan.FromSeconds(2));

    public ObservableCollection<ITestItem> TestItems { get; }

    [ObservableProperty]
    private ITestItem? selectedItem;

    [ObservableProperty]
    private bool isMenuOpen;

    public MainWindowViewModel()
    {
        var app = Application.Current as App;
        var notifyService = app?.Services?.GetService<ISnackNotifyService>();
        if (notifyService is not null)
        {
            notifyService.MessageQueue = SnackbarMessageQueue;
        }

        TestItems = [.. CreatePages()];
        SelectedItem = TestItems[0];
    }

    private static IEnumerable<ITestItem> CreatePages()
    {
        yield return new TestItem<HomePage, HomeViewModel>("Home");
        yield return new TestItem<ConnectionTestPage, ConnectionTestViewModel>("Connection Test");
        yield return new TestItem<SelectionTestPage, SelectionTestViewModel>("Selection Test");
        yield return new TestItem<HighlightTestPage, HighlightTestViewModel>("Highlight Test");
        yield return new TestItem<IntersectionPage, IntersectionTestViewModel>("Intersection Test");
        yield return new TestItem<InquireTestPage, InquireTestViewModel>("Inquirement Test");
        yield return new TestItem<PointInquireTestPage, PointInquireTestViewModel>("Point inquire Test");
        yield return new TestItem<TangentTestPage, TangentTestViewModel>("Tangent Test");
        yield return new TestItem<ProjectionTestPage, ProjectionTestViewModel>("Projection Test");
        yield return new TestItem<TrimTestPage, TrimTestViewModel>("Trim Test");
        yield return new TestItem<OffsetTestPage, OffsetTestViewModel>("Offset Test");
        yield return new TestItem<CurveIntersectTestPage, CurveIntersectTestViewModel>("Curve intersect Test");
        yield return new TestItem<CommentTestPage, CommentTestViewModel>("Comment markup Test");
        yield return new TestItem<GeodesicTestPage, GeodesicTestViewModel>("Geodesic Test");
        yield return new TestItem<CurveDivisionTest, CurveDivisionTestViewModel>("Curve division Test");
        yield return new TestItem<SketchTestPage, SketchTestViewModel>("Sketch test");
        yield return new TestItem<MultipleDeletionTestPage, MultipleDeletionTestViewModel>("Multiple del test");
        yield return new TestItem<CurveOperationTestPage, CurveOperationTestViewModel>("Curve Ops test");
        yield return new TestItem<DbTestPage, DbTestViewModel>("DB test");
        yield return new TestItem<LoopOperationTestPage, LoopOperationTestViewModel>("Loop Op. test");
        yield return new TestItem<ExportTestPage, ExportTestViewModel>("Export test");
        yield return new TestItem<PlyDartTestPage, PlyDartTestViewModel>("Create dart test");
        yield return new TestItem<SurfaceSewTestPage, SurfaceSewTestViewModel>("Surface Sew test");
        yield return new TestItem<PlySectionTestPage, PlySectionTestViewModel>("3d section test");
        yield return new TestItem<PrimitiveTestPage, PrimitiveTestViewModel>("Primitives test");
        yield return new TestItem<LoopCurveOpsTestPage, LoopCurveOpsTestViewModel>("Loop and curve test");
        yield return new TestItem<MBDTestPage, MBDTestViewModel>("MBD test");
    }

    partial void OnSelectedItemChanged(ITestItem? value)
    {
        IsMenuOpen = false;
    }
}
